package com.zero.manage.web.components.entity.rbac;

import com.zero.manage.web.components.base.BaseTreeEntity;
import io.gitee.zerowsh.enums.ToolEnums;
import com.zero.manage.web.utils.validated.SysPowerGroupSequenceProvider;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.validator.group.GroupSequenceProvider;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 菜单--填写图标，名称，备注
 * 路由--填写图标，名称，资源路径，是否缓存
 * 权限--填写接口地址，名称
 *
 * @author zero
 */

@Entity
@Table(name = "sys_power")
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
@GroupSequenceProvider(SysPowerGroupSequenceProvider.class)
@ApiModel("系统权限")
public class SysPowerEntity extends BaseTreeEntity {
    @Column(name = "type")
    @ApiModelProperty("类型")
    @NotNull(message = "类型必填")
    @Enumerated(EnumType.STRING)
    private ToolEnums.PowerTypeEnums type;

    @Column(name = "sort")
    @ApiModelProperty("排序")
    private Integer sort;

    @Column(name = "url")
    @ApiModelProperty("接口地址")
    @NotBlank(groups = UrlGroup.class, message = "接口地址必填")
    private String url;

    /**
     * 前端路由地址
     */
    @Column(name = "path")
    @ApiModelProperty("资源路径")
    @NotBlank(groups = PathGroup.class, message = "资源路径必填")
    private String path;

    /**
     * 前端路由是否缓存
     */
    @Column(name = "cache")
    @ApiModelProperty("是否缓存")
    @Enumerated(EnumType.STRING)
    private ToolEnums.WhetherEnums cache;

    @Column(name = "icon")
    @ApiModelProperty("图标")
    private String icon;

    /**
     * 定义专属的业务逻辑分组
     */
    public interface PathGroup {
    }

    public interface UrlGroup {
    }
}
